package com.ykdl.member.kid.gears;

import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;

import com.ykdl.member.KidApp;
import com.ykdl.member.base.GlobalContext;
import com.ykdl.member.constant.KidAction;
import com.ykdl.member.kid.models.ArticleBean;
import com.ykdl.member.kid.regandlogin.RegAndLoginActivity;
import com.ykdl.member.kid.util.AccessTokenKeeper;
import com.ykdl.member.kid.util.ShareUtil;
import com.ykdl.member.kid.widget.dialog.DialogCallBack;
import com.ykdl.member.kid.widget.dialog.DialogImpl;
import com.ykdl.member.kid.widget.dialog.IDialog;

public class ArticleWapActivity extends WebViewActivity {
	
	String url = null;
	private String article_id;
	private  AccessTokenKeeper mTokenKeeper;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void getIntentData() {
		 mTokenKeeper = new AccessTokenKeeper(GlobalContext.mContext);
		 article_id = this.getIntent().getStringExtra("article_id");
		 url = GlobalContext.PROJECT_SERVER +"/api/v1/articles/" + article_id+"?v=1&access_token=" + mTokenKeeper.getmAccessToken(); 
	}
	private void finishActivity(){
		this.finish();
	}
	private void startActivity(){
		Intent  intent = new Intent(mContext, RegAndLoginActivity.class);
		intent.putExtra(KidAction.FROM, "");
		this.startActivity(intent);
	}
	@Override
	protected void setWapTitle() {
		String title = "专家讲堂";
		/*if(bean.getTitle() !=null){
			if(bean.getTitle().length() > 5){
				title = bean.getTitle().substring(0, 4)+"...";
			}
		}*/
		tv_title.setText(title);
	}
	@Override
	protected void startLoadUrl() {
		webView.loadUrl(url);
	}
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		
		if(mTokenKeeper.getmisAnonymous()){
			 DialogImpl  dialog = new DialogImpl();
			 dialog.showDialog(this, "注意", "注册登录后，专家将针对宝宝年龄教你育儿", false, new DialogCallBack(){

				@Override
				public void onClick(int what) {
					switch (what) {
					case IDialog.YES://升级
						startActivity();
						finishActivity();
						break;
					case IDialog.CANCLE://退出程序，强制升级
						finishActivity();
						break;
					default:
						break;
					}
				}
				 
			 });
		 }
	}
	/**
	 * 检测请求url，手动进行重定向
	 */
	@Override
	protected boolean overrideUrlLoading(WebView view, String url) {
		return false;
	}
	public void doShare() {
		ShareUtil  share = new ShareUtil(this);
		share.show(url);
	}


}
